{% extends "PlatBundle::layout.html.twig" %}


{% block title %}{% if data.info.id == 0 %}添加{% else %}编辑{% endif %}超级管理员帐号{% endblock %}

{% block css %}{% endblock %}


{% block top %}
    {#{{ dump() }}#}
    {{ parent() }}
{% endblock %}



    {% block left_body_top %}
        {{ parent() }}
    {% endblock %}

    {% block left_body %}
        {{ parent() }}
    {% endblock %}

    {% block right_body %}
    <div class="page-header">
        <div class="page-right-top">
            <div class="right-top">
                <span class="right-title">系统设置</span>
            </div>
            <div class="top-nav">超级管理员账号管理</div>
            <span class="r-arrow top-r-arrow"></span>
            <div class="top-nav top-nav-active">{% if data.info.id == 0 %}添加{% else %}编辑{% endif %}</div>
        </div>
        <div class="main-content">
            <div class="mes-content">

                <div class="main-mes-content">
                    <form id="comMesBtn">
                        <div class="com-list">
                            <div class="display">
                                <div class="com-list-box fl">
                                    <div class="com-left fl">所属区域</div>

                                    {% if data.info.id > 0 %}
                                        <input type="text" readonly data-id="{{ data.info.district_id }}" value="{{ data.info.district_name }}">

                                    {% else %}

                                    <select class="com-select fl" name="district_id">
                                        <option value="0">请选择所属区域</option>
                                        {% for item in data.district %}
                                            <option value="{{ item.id }}">{{ item.name }}</option>
                                        {% endfor %}
                                    </select>

                                    {% endif %}


                                    <div class="clearfix"></div>
                                </div>

                                <div class="clearfix"></div>
                            </div>

                            <div class="com-list-box">
                                <div class="com-left fl">管理员账号</div>
                                <input type="text" {% if data.info.id == 0 %} name="phone" {% endif %} {% if data.info.id > 0 %}readonly  value="{{ data.info.phone }}" {% endif %} class="is-change pop-com-input" placeholder="请输入管理员账号">
                            </div>

                            <input type="hidden" name="id">

                            <div class="com-list-box">
                                <div class="com-left fl">管理员名称</div>
                                <input type="text" name="nickname" value="{% if data.info.id > 0 %}{{ data.info.nickname }}{% endif %}"  class="is-change pop-com-input" placeholder="请输入管理员名称">
                            </div>

                            <div class="com-list-box">
                                <div class="com-left fl">管理员姓名</div>
                                <input type="text" name="realname" value="{% if data.info.id > 0 %}{{ data.info.realname }}{% endif %}" class="is-change pop-com-input" placeholder="请输入管理员姓名">
                            </div>

                            <div class="com-list-box">
                                <div class="com-left fl">邮箱</div>
                                <input type="text" name="email" value="{% if data.info.id > 0 %}{{ data.info.email }}{% endif %}" class="is-change pop-com-input" placeholder="请输入邮箱地址">
                            </div>

                            <div class="clearfix"></div>
                            <div class="add-mem-box" style="margin-top: 40px;">
                                <div class="com-left fl"></div>
                                <div class="acc-opera-btn fl mem-btn p-first-btn">保存</div>
                                <div class="acc-opera-btn fl mem-cancel">取消</div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    {% endblock %}

{% block box %}{% endblock %}

{% block javascript %}
<script type="text/javascript">
    $(function () {

        SidebarHighlighting('8');
        SonSidebar("8","3");

        // 属性选择
        $('.radio-icon').on('click', function () {
            $('.radio-icon').removeClass('radio-icon-check');
            $(this).addClass('radio-icon-check');
        });

        // 取消
        $(".mem-cancel").click(function(){
            location.href = "{{ path('plat_admin_account_list') }}";
        })

        // 点击保存
        $('.p-first-btn').on('click', function() {

            $("input[name='id']").val("{{ data.info.id }}");
            var param = $('#comMesBtn').serializeObject();

            console.log(param);

            {% if data.info.id == 0 %}
            if(param.district_id == "" || param.district_id == "0"){
                popStatus(2, '请选择区域', 1, '', true);
                return;
            }

            if(param.phone == ""){
                popStatus(2, '请输入帐号', 1, '', true);
                return;
            }

            {% endif %}

            if ($.trim(param.nickname) == '') {
                popStatus(2, '请填写管理员名称', 1, '', true);
                return;
            }

            if ($.trim(param.realname) == '') {
                popStatus(2, '请填写管理员姓名', 1, '', true);
                return;
            }

            if ($.trim(param.email) == '') {
                popStatus(2, '请填写邮箱', 1, '', true);
                return;
            }

            var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;

            if(!myreg.test(param.email)) {
                popStatus(2, '请输入有效的邮箱', 1, '', true);
                return;
            }

            $.post("{{ path('api_platform_edit_admin_account') }}",param,function(data){
                console.log(data);

                if(data.errorCode == 0){
                    popStatus(1, data.message, 1,"{{ path('plat_admin_account_list') }}", true);
                } else {
                    popStatus(2, data.message, 1,'', true);
                }


            })


        })

    })
</script>
{% endblock %}